import request from '../../utils/request'
import { LockDayDto } from '../personalChannel'

export interface CreatePeerCarDto {
  carName: string
  brand: string
  price: number
  frameNumber?: string
  safeCount?: number
  mileage?: number
  registrationDate?: string
  homeLocation?: string
  emissionStandard?: string
  energy?: number
  insuranceDate?: string
  gearbox?: string
  annualInspection?: string
  location?: string
  usingNature?: number
  phone: string
  description?: string
  userId: string
}
/**
 * 发布同行车源
 * @param {CreatePeerCarDto} data 
 */
export const createPeerCar = (data: CreatePeerCarDto) => request('/api/wxpeercar', 'POST', data) as Promise<Result<ListPeerCar>>

/**
 * 分页获取同行车源列表
 * @param {number} page 
 * @param {string} brand 
 */
export const getPeerCarPage = (page: number, brand: string) => request(`/api/wxpeercar/page?page=${page}&brand=${brand}`, 'GET') as Promise<PageResult<ListPeerCar[]>>

export const getPeerCarByUser = (userId: string) => request(`/api/wxpeercar/user?userId=${userId}`, 'GET') as Promise<Result<ListPeerCar[]>>

export const getPeerCarDetail = (id: string) => request(`/api/wxpeercar?id=${id}`, 'GET') as Promise<Result<ListPeerCar>>

export const getPeerImg = (peerId: string) => request(`/api/wxpeercar/img?peerId=${peerId}`, 'GET')

export const createPeerImg = (data: { url: string, peerId: string }) => request('/api/wxpeercar/img', 'POST', data) as Promise<Result<string>>

/**
 * 锁定同行车源
 * @param data 
 */
export const lockPeer = (data: LockDayDto) => request(`/api/wxpeercar/lock`, 'POST', data) as Promise<Result<WxUser>>

export const checkOuted = (id: string) => request(`/api/wxpeercar/checkOut/${id}`, 'GET') as Promise<Result<boolean>>

export const checkExpire = (id: string) => request(`/api/wxpeercar/expire/${id}`, 'GET') as Promise<Result<boolean>>